/*
 * @Description:
 * @Date: 2024-06-25 21:50:29
 * @LastEditTime: 2024-10-15 11:49:59
 */
import { defineStore } from 'pinia'
import { ref } from 'vue'

const initState = {
  hint: null,
  residentId: null,
  gridMemberId: null,
  accessToken: null,
  isPartyMember: null,
  name: null,
  phone: null,
  type: null,
  userId: null,
  isLogined: null,
}

export const useUserStore = defineStore(
  'user',
  () => {
    const userInfo = ref<IUserInfo>({ ...initState })

    const setUserInfo = (val: IUserInfo) => {
      userInfo.value = val
    }
    const setIsLogined = (value) => {
      userInfo.value.isLogined = value
    }
    const setResidentId = (value) => {
      userInfo.value.residentId = value
    }
    const setGridMemberId = (value) => {
      userInfo.value.gridMemberId = value
    }
    const clearUserInfo = () => {
      userInfo.value = { ...initState }
    }
    // 一般没有reset需求，不需要的可以删除
    const reset = () => {
      userInfo.value = { ...initState }
    }

    return {
      userInfo,
      setUserInfo,
      setIsLogined,
      setResidentId,
      clearUserInfo,
      setGridMemberId,
      reset,
    }
  },
  {
    persist: true,
  },
)
